package com.weishi;

import com.weishi.common.enums.RedisConstants;
import com.weishi.framework.redis.RedisCache;
import com.weishi.project.training.domain.Sportsman;
import com.weishi.project.training.service.ISportsmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ScheduledJob {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private ISportsmanService sportsmanService;

    @Scheduled(cron = "0 03 15 ? * *")
    public void executeSync2Redis() {
        List<Sportsman> sportsmanList = sportsmanService.selectSportsmanList(new Sportsman());
        for (Sportsman sportsman : sportsmanList) {
            redisCache.setCacheObject(RedisConstants.Sportsman_Info_Prefix + sportsman.getId(), sportsman);
        }
    }

}
